package lt.marsrutai.mobile.android.util;

import java.util.Calendar;
import java.util.List;

import lt.marsrutai.mobile.android.model.ArrivalTime;
import lt.marsrutai.mobile.android.model.enums.DateTime;

public class NextDepartures {

    private String returnString = "??";

    public NextDepartures(List<ArrivalTime> trackStopTimes) {
        final int AFTER = 1;

        DateTime now = new DateTime();
        StringBuffer nextDepartures = new StringBuffer();

        for (ArrivalTime stopTime: trackStopTimes) {
            if (CalendarHourMinuteComparator.INSTANCE.compare(stopTime.getScheduledTime(), now.getCalendar()) == AFTER) {
                nextDepartures.append(stopTime.getScheduledTime().get(Calendar.HOUR_OF_DAY));
                nextDepartures.append(":");
                
                String minute = String.valueOf(stopTime.getScheduledTime().get(Calendar.MINUTE));
                if (minute.length() == 1) {
                    minute = "0" + minute;
                }
                
                nextDepartures.append(minute);
                nextDepartures.append(" ");
            }
        }

        returnString = nextDepartures.toString();
    }

    @Override
    public String toString() {
        return returnString;
    }

}
